/**
 * 日期格式化
 * @param date
 * @param fmt 默认 yyyy-MM-dd
 * @returns {string}
 */
export function date2Str(date, fmt = 'yyyy-MM-dd') {
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const day = date.getDate().toString().padStart(2, '0');
  return fmt.replace('yyyy', year)
    .replace('MM', month)
    .replace('dd', day)
}

/**
 * 时间时间格式化
 * @param date
 * @param fmt 默认 yyyy-MM-dd HH:mm:ss
 * @returns {string}
 */
export function dateTime2Str(date, fmt = 'yyyy-MM-dd HH:mm:ss') {
  const year = date.getFullYear();
  const month = (date.getMonth() + 1).toString().padStart(2, '0');
  const day = date.getDate().toString().padStart(2, '0');
  const hours = date.getHours().toString().padStart(2, '0');
  const minutes = date.getMinutes().toString().padStart(2, '0');
  const seconds = date.getSeconds().toString().padStart(2, '0');
  return fmt.replace('yyyy', year)
    .replace('MM', month)
    .replace('dd', day)
    .replace('HH', hours)
    .replace('mm', minutes)
    .replace('ss', seconds)
}
